﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Gmis.Public;
namespace Gmis.Web.Manage.Affairs
{
    /// <summary>
    /// LeaveWordManage1 的摘要说明
    /// </summary>
    public class LeaveWordManage1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            

            string action = context.Request["Action"].ToLower();

            if (string.IsNullOrEmpty(action))
            {
                context.Response.Write(CommonFunction.failure("无指定操作"));
            }
            else
            {
                //ProcessAction();
                switch (action.ToLower())
                {
                    case "reply":
                        ProcessReplyAction(context);
                        break;

                    case "delete":
                        ProcessDeleteAction(context);
                        break;
                    case "deleteall":
                        ProcessDeleteAllAction(context);
                        break;
                   
                }
            }
        }
        private void ProcessDeleteAllAction(HttpContext context)
        {
            //throw new NotImplementedException();
            string ids = context.Request.Form["ids"];
            if (ids != string.Empty)
            {

                string[] idsList = ids.Split(',');
                ids = string.Empty;
                for (int i = 0; i < idsList.Length; i++)
                {

                    idsList[i] = "'" + idsList[i] + "'";
                    if (i != 0)
                    {
                        ids += ",";
                    }
                    ids += idsList[i];

                }

                Gmis.BLL.LeaveWord bll = new BLL.LeaveWord();
                try
                {
                    if (bll.DeleteList(ids))
                    {
                        context.Response.Write(CommonFunction.success());
                    }
                    else
                    {
                        context.Response.Write(CommonFunction.failure());

                    }
                }
                catch
                {
                    context.Response.Write(CommonFunction.failure());

                }
            }

        }
        private void ProcessDeleteAction(HttpContext context)
        {
            //throw new NotImplementedException();
            Gmis.BLL.LeaveWord bll = new BLL.LeaveWord();
            try
            {
                bll.Delete(context.Request["Id"]);
                context.Response.Write(CommonFunction.success("", "LeaveWordManage"));
            }
            catch
            {
                context.Response.Write(CommonFunction.failure());

            }
        }
        private void ProcessReplyAction(HttpContext context)
        {
            //throw new NotImplementedException();
            Gmis.Model.LeaveWord model = new Model.LeaveWord();
            model.replyPerson = "";
            model.Id = context.Request["Id"];
            model.IsShow = context.Request["IsShow"] == null ? false : true;
            model.replyContents = context.Request["replyContents"];
            model.replyTime = DateTime.Now;
            Gmis.BLL.LeaveWord bll = new BLL.LeaveWord();
            try
            {
                bll.Reply(model);
                context.Response.Write(CommonFunction.success("", "LeaveWordManage"));
            }
            catch
            {
                context.Response.Write(CommonFunction.failure());

            }
        }
       
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}